import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import useUserStore from '@/store/user.js'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  linkActiveClass: 'link-active',
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      redirect: '/home/sell',
      children: [   
        {
          path: '/home/sell',
          name: 'sell',
          component: () => import('@/views/CourseListPage.vue')
        },
        {
          path: '/home/school',
          name: 'school',
          component: () => import('../views/HomeSchool.vue')
        },
        {
          path: '/home/learn',
          name: 'learn',
          component: () => import('../views/HomeLearn.vue')
        },
        {
          path: '/home/tiku',
          name: 'tiku',
          component: () => import('../views/HomeTiku.vue')
        },
        {
          path: '/home/mine',
          name: 'mine',
          component: () => import('../views/HomeMine.vue')
        }
      ]
    },
    {
      path: '/:pathMatch(.*)',
      name: 'notfound',
      component: () => import('@/views/NoFountPage.vue')
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginPage.vue')
    },
    {
      path: '/course/:courseId',
      name: 'courseDetail',
      component: () => import('../views/CourseDetailPage.vue'),
      props: true,
      beforeEnter: (to, from , next) => {
        const user = useUserStore()
        if (user.loginInfo.isLogin) {
          next()
        }else{
          next('/login')
        }
      }
  },
    // {
    //   path: '/login/:number/:password',
    //   name: 'loginwithguard',
    //   component: () => import('../views/LoginPage.vue'),
    //   props: true,
    //   beforeEnter: (to, from , next) => {
    //     const { number, password } = to.params
        
    //     if (password === '123456') {
    //       next()
    //     }else{
    //       next('/about')
    //     }
    //   }
    // }
  ]
})

export default router
